<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The SimpleXMLElement class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="simplexml.examples-errors.html">« Dealing with XML errors</a></li>
      <li style="float: right;"><a href="simplexmlelement.addattribute.html">SimpleXMLElement::addAttribute »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.simplexml.html">SimpleXML</a></li>
    <li>The SimpleXMLElement class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.simplexmlelement" class="reference">
 <h1 class="title">The SimpleXMLElement class</h1>
 
 
 <div class="partintro"><p class="verinfo">(PHP 5, PHP 7, PHP 8)</p>
 

  <div class="section" id="simplexmlelement.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    Represents an element in an XML document.
   </p>
  </div>

 
  <div class="section" id="simplexmlelement.synopsis">
   <h2 class="title">类摘要</h2>
 

   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">SimpleXMLElement</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.stringable.html" class="interfacename">Stringable</a></span><span class="oointerface">,  <a href="class.countable.html" class="interfacename">Countable</a></span><span class="oointerface">,  <a href="class.recursiveiterator.html" class="interfacename">RecursiveIterator</a></span> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.construct.html" class="methodname">__construct</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$dataIsURL</code><span class="initializer"> = <strong><code>false</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$namespaceOrPrefix</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$isPrefix</code><span class="initializer"> = <strong><code>false</code></strong></span></span><br>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.addattribute.html" class="methodname">addAttribute</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$qualifiedName</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$namespace</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.addchild.html" class="methodname">addChild</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$qualifiedName</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$value</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$namespace</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">?</span><span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.asxml.html" class="methodname">asXML</a></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$filename</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">string</span>|<span class="type">bool</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.attributes.html" class="methodname">attributes</a></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$namespaceOrPrefix</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$isPrefix</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type"><span class="type">?</span><span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.children.html" class="methodname">children</a></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$namespaceOrPrefix</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$isPrefix</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type"><span class="type">?</span><span class="type"><a href="class.simplexmlelement.html" class="type SimpleXMLElement">SimpleXMLElement</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.count.html" class="methodname">count</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.getdocnamespaces.html" class="methodname">getDocNamespaces</a></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$recursive</code><span class="initializer"> = <strong><code>false</code></strong></span></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$fromRoot</code><span class="initializer"> = <strong><code>true</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.getname.html" class="methodname">getName</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.getnamespaces.html" class="methodname">getNamespaces</a></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$recursive</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.registerxpathnamespace.html" class="methodname">registerXPathNamespace</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$prefix</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$namespace</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.tostring.html" class="methodname">__toString</a></span>(): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="simplexmlelement.xpath.html" class="methodname">xpath</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$expression</code></span>): <span class="type"><span class="type">array</span>|<span class="type">null</span>|<span class="type"><span class="type false">false</span></span></span></div>

   }</div>

 
  </div>

  <div class="section">
   <h2 class="title">更新日志</h2>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        <span class="classname"><strong class="classname">SimpleXMLElement</strong></span> implements
        <span class="interfacename"><a href="class.stringable.html" class="interfacename">Stringable</a></span>,
        <span class="interfacename"><a href="class.countable.html" class="interfacename">Countable</a></span>,
        and <span class="interfacename"><a href="class.recursiveiterator.html" class="interfacename">RecursiveIterator</a></span> now.
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>
 
 </div>
 
 

































 














































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="simplexmlelement.addattribute.html">SimpleXMLElement::addAttribute</a> — Adds an attribute to the SimpleXML element</li><li><a href="simplexmlelement.addchild.html">SimpleXMLElement::addChild</a> — Adds a child element to the XML node</li><li><a href="simplexmlelement.asxml.html">SimpleXMLElement::asXML</a> — Return a well-formed XML string based on SimpleXML element</li><li><a href="simplexmlelement.attributes.html">SimpleXMLElement::attributes</a> — Identifies an element's attributes</li><li><a href="simplexmlelement.children.html">SimpleXMLElement::children</a> — Finds children of given node</li><li><a href="simplexmlelement.construct.html">SimpleXMLElement::__construct</a> — Creates a new SimpleXMLElement object</li><li><a href="simplexmlelement.count.html">SimpleXMLElement::count</a> — Counts the children of an element</li><li><a href="simplexmlelement.getdocnamespaces.html">SimpleXMLElement::getDocNamespaces</a> — Returns namespaces declared in document</li><li><a href="simplexmlelement.getname.html">SimpleXMLElement::getName</a> — Gets the name of the XML element</li><li><a href="simplexmlelement.getnamespaces.html">SimpleXMLElement::getNamespaces</a> — Returns namespaces used in document</li><li><a href="simplexmlelement.registerxpathnamespace.html">SimpleXMLElement::registerXPathNamespace</a> — Creates a prefix/ns context for the next XPath query</li><li><a href="simplexmlelement.savexml.html">SimpleXMLElement::saveXML</a> — 别名 SimpleXMLElement::asXML</li><li><a href="simplexmlelement.tostring.html">SimpleXMLElement::__toString</a> — Returns the string content</li><li><a href="simplexmlelement.xpath.html">SimpleXMLElement::xpath</a> — Runs XPath query on XML data</li></ul>
</div>
</div></div></body></html>